<script type="text/javascript">
<!--{literal}
$(document).ready
(
    function()
    {
	$('table.grid#datagrid')
	    .jqGrid
	    ({
		datatype:	'local',
		colNames:	['От (мин.)','До (мин.)','Стоимость (руб.)'],
		colModel:
		[
		    {name:'delay_start',sortable:false},
		    {name:'delay_stop',sortable:false},
		    {name:'cost',editable:true},
		],
		rownumbers:	true,
		pager:		'datagrid-p',

		ondblClickRow:	function(rowid)
				{
				    if ( window.confirm('Удалить выбранный диапазон?') )
				    {
					$.get
					(
					    'dictionaries.xml',
					    {
						name:	'fine_settings',
						do:	'delete',
						id:	rowid
					    },
					    function(xml)
					    {
						if ( $(xml).find('result').attr('status') != 200 )
						{
						    alert('Ошибка');
						}
						reloadGrid();
					    },
					    'xml'
					);
				    }
				},

// Редактирование таблицы
		cellEdit:	true,
		cellurl:	'dictionaries.xml?name=fine_settings&do=update',
		cellsubmit:	'remote'
	    });

	$('div.dialog#add-range')
	    .dialog
	    (
		'option',
		{
		    title:	'Добавление интервала',
		    resizable:	false,
		    modal:	true,
		    buttons:
		    {
			'OK':	function()
				{
				    $.post
				    (
					'dictionaries.xml',
					$('div.dialog#add-range').find('form').serialize(),
					function(xml)
					{
					    if ( $(xml).find('result').attr('status') != 200 )
					    {
						alert('Ошибка');
					    }

					    $('div.dialog#add-range').dialog('close');
					    reloadGrid();
					},
					'xml'
				    );
				}
		    }
		}
	    );

	$('input:button#add-range-b').click(function(){$('div.dialog#add-range').dialog('open');});

	function reloadGrid()
	{
	    $.get
	    (
		'dictionaries.xml',
		{ name: 'fine_settings' },
		function(xml)
		{
		    $('table.grid#datagrid')
			.setGridParam({datatype:'xmlstring',datastr:xml})
			.trigger('reloadGrid');
		},
		'xml'
	    );
	}

	reloadGrid();
    }
);
{/literal}-->
</script>

<div class="dialog" id="add-range">
    <form>
	<input type="hidden" name="name" value="fine_settings"/>
	<input type="hidden" name="do" value="add"/>

	<table align="center">
	    <tr>
		<td align="right" style="font-weight:bold;">Начало интервала</td>
		<td><input type="text" name="delay_start"/></td>
	    </tr>
	    <tr>
		<td align="right" style="font-weight:bold;">Конец интервала</td>
		<td><input type="text" name="delay_stop"/></td>
	    </tr>
	    <tr>
		<td align="right" style="font-weight:bold;">Стоимость</td>
		<td><input type="text" name="cost"/></td>
	    </tr>
	</table>
    </form>
</div>

<input type="button" id="add-range-b" value="Добавить интервал" class="button"/>
